using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class SelectionMenu : InteractiveDisplay {

	public int _selectedIndex;
	//public SimpleMenuItem [] _menuItems;
	private SortedDictionary< int, SimpleMenuItem> _menuItems = new SortedDictionary<int, SimpleMenuItem>();
	
	public SortedDictionary< int, SimpleMenuItem> MenuItems {
		 get {
				 return _menuItems;
			}
	}
	
	public override void DoSomeThing(KeyCode k){

		switch (k) {
			case KeyCode.UpArrow:
				Up ();
				break;
			case KeyCode.DownArrow:
				Down();
				break;
			case KeyCode.Return:
				Run (k);
				break;
		}
		
	}
	
	public override void DoSomeThing(KeyCode k , ControlSceme c){
		
		if (k == c._up) {
			Up ();
		} else if (k == c._down) {
			Down();
		} else if (k == c._space ) {
			Run (k);
		}
		
	}
	
	
	public virtual void Up() {
		_menuItems[_selectedIndex]._selected = false;
		_selectedIndex--;
		if (_selectedIndex < 0) {
			_selectedIndex += _menuItems.Count;
		}
		_menuItems[_selectedIndex]._selected = true;
	}
	
	public virtual void Down(){
		_menuItems[_selectedIndex]._selected = false;
		_selectedIndex++;
		if (_selectedIndex >= _menuItems.Count) {
			_selectedIndex -= _menuItems.Count;
		}
		_menuItems[_selectedIndex]._selected = true;
	}
	
	public virtual void Run(KeyCode k) {
		_menuItems[_selectedIndex].DoSomeThing(k);
	}

}
